import * as echarts from "echarts";

function setOption(department, count) {
  let filledDepartment = [];
  let filledCount = [];

  for (let i = 0; i < 23; i++) {
    if (department.includes(getDepartmentName(i))) {
      filledDepartment.push(getDepartmentName(i));
      filledCount.push(count[department.indexOf(getDepartmentName(i))]);
    } else {
      filledDepartment.push(getDepartmentName(i));
      filledCount.push(0);
    }
  }

  let option = {
    tooltip: {
      trigger: 'axis'
    },
    title: {
      text: '各部门诉求数统计',
      left: '5%',
      top: '5%',
      textStyle: {
        color: '#007AFF',
        fontSize: 16
      }
    },
    xAxis: {
      type: 'value'
    },
    yAxis: {
      type: 'category',
      data: filledDepartment
    },
    grid: {
      left: '3%',
      right: '8%',
      bottom: '10%',
      containLabel: true
    },
    series: [
      {
        data: filledCount,
        type: 'bar',
        showBackground: true,
        itemStyle: {
          color: '#0262F7'
        },
        label: {
          show: true,
          position: 'right',
          distance: 10,
          color: '#000',
        },
        backgroundStyle: {
          color: 'rgba(180, 180, 180, 0.2)'
        }
      }
    ]
  };
  return option;
}

function getDepartmentName(index) {
  switch (index) {
    case 0: return '企服';
    case 1: return '便民';
    case 2: return '招商1';
    case 3: return '招商2';
    case 4: return '经发';
    case 5: return '科技人才';
    case 6: return '统计';
    case 7: return '安监';
    case 8: return '环保';
    case 9: return '建设';
    case 10: return '资规';
    case 11: return '总工会';
    case 12: return '消安委';
    case 13: return '联动';
    case 14: return '城管';
    case 15: return '公安';
    case 16: return '交警';
    case 17: return '文教';
    case 18: return '农经农技';
    case 19: return '水利';
    case 20: return '人社';
    case 21: return '司法';
    case 22: return '商会';
    default: return '';
  }

}

export default {
  setOption
}